// Copyright (c) [2021] [daifang]
// [Dcomponent] is licensed under Mulan PSL v2.
// You can use this software according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of Mulan PSL v2 at:
//          http://license.coscl.org.cn/MulanPSL2
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
// See the Mulan PSL v2 for more details.
import Content from "./content"
import ReactDom from 'react-dom'
import './index.less'
class Toast {
    store = []
    create = (type, content, option)=>{
        // console.log(this.body)
        let div = document.getElementsByClassName('toast-container')[0];
        if(div === undefined){
            let divv = document.createElement('div')
            divv.classList.add('toast-container')
            document.body.append(divv)
        }
        div = document.getElementsByClassName('toast-container')[0]
        if(div.children.length === 0){
            let toast = <Content
                type={type}
                option = {option}
            >
                {content}
            </Content>
            ReactDom.render(toast, div)
        }else{

        }
    }
    destory = ()=>{
        let div = document.getElementsByClassName('toast-container')[0]
        if(div)
            document.body.removeChild(div)
    }
    info = (content,option)=>{
        this.create('info',content,option)
    }
    success = (content,option)=>{
        this.create('success',content,option)
    }
    error = (content,option)=>{
        this.create('error',content,option)
    }
    warn = (content,option)=>{
        this.create('warn',content,option)
    }
}
let toast = new Toast()
export default toast